
using Youz.Common.Entity;
using Youz.Common.Helper;
using Youz.CreditRepay.DAL;
using Youz.CreditRepay.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using Youz.Common.BLL;

namespace Youz.CreditRepay.BLL
{
    /// <summary>
    /// Pay_Records BLL Class
    /// </summary>
    public partial class Pay_RecordsBLL : BaseBLL
    {
		Pay_RecordsDAL dal;
		
        public Pay_RecordsBLL()
        {
			dal = new Pay_RecordsDAL();
			base.ModuleName = "Pay_Records";
            base.MenuName = "Pay_Records";
		}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Pay_Records model)
        {
            var r = dal.Add(model);
            			
			base.WriteOperationLog(OperationType.Add, r, Core.GetJsonByObjectHaveTime(model));

            return r;
        }

        public string Add(PaymentType type, PayTradeType tradeType, string member, decimal amount, object parentID)
        {
            var model = new Pay_Records
            {
                PayType = type,
                TradeNo = GenerateTradeNo(),
                TradeTime = DateTime.Now,
                TradeName = GetTradeTypeText(tradeType),
                Payer = member,
                Amount = amount,
                Status = PayRecordsStatus.Pay,
                ParentID = parentID.ToString()
            };

            if (Add(model))
            {
                return model.TradeNo;
            }
            else
            {
                return string.Empty;
            }
        }

        public string GetTradeTypeText(PayTradeType tradeType)
        {
            string text = string.Empty;
            switch (tradeType)
            {
                case PayTradeType.Getcash:
                    text = "信用卡取现";
                    break;
                case PayTradeType.Repay:
                    text = "信用卡还款计划";
                    break;
                case PayTradeType.Recharge:
                    text = "零钱充值";
                    break;
                case PayTradeType.Withdraw:
                    text = "零钱取现";
                    break;
            }
            return text;
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Pay_Records model)
        {
            var r = dal.Update(model);
			
			base.WriteOperationLog(OperationType.Update, r, Core.GetJsonByObjectHaveTime(model));

            return r;
        }

        /// <summary>
        /// 更新记录状态
        /// </summary>
        /// <param name="tradeNo"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public bool UpdateStatus(string tradeNo, PayRecordsStatus status)
        {
            return dal.UpdateStatus(tradeNo, status);
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Int64 ID)
        {
            var r = dal.Delete(ID);
			
			base.WriteOperationLog(OperationType.Delete, r, ID);

            return r;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Pay_Records Get(Int64 ID)
        {
            return dal.Get(ID);
        }
		
		/// <summary>
        /// 得到一个JSON对象
        /// </summary>
        public string GetJson(Int64 ID)
        {
            return Core.GetJsonByObject(Get(ID));
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            return dal.GetsWhere(sqlWhere);
        }
		
		/// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int top, string sqlWhere, string filedOrder)
        {
            return dal.Gets(top, sqlWhere, filedOrder);
        }
		
		/// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            return dal.GetRecordCount(sqlWhere);
        }
		
		/// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            return dal.Gets(sqlWhere, pageindex, pagesize, out total, cmdParms);
        }
        #endregion  成员方法

        /// <summary>
        /// 将支付记录更新到对应的充值记录中
        /// </summary>
        /// <returns></returns>
        public string UpdateToRecharge()
        {
            return dal.UpdateToRecharge();
        }

        public Pay_Records Get(string tradeNo)
        {
            return dal.Get(tradeNo);
        }

        /// <summary>
        /// 生成ID
        /// </summary>
        /// <returns></returns>
        public string GenerateTradeNo()
        {
            return dal.GenerateTradeNo();
        }
    }
}


  